﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using HtmlAgilityPack;

namespace WSManager.Logic.Transformation.Articles
{
    public class HtmlArticleTransformer: XmlArticleTransformer
    {
        public HtmlArticleTransformer() : base("Xslts/Html.xslt") { }

        public override XElement ConvertStream(System.IO.Stream stream)
        {
            var html = new HtmlDocument();
            html.Load(stream);
            html.OptionOutputAsXml = true;
            var memstr = new MemoryStream((int)(stream.Length * 1.2));
            html.Save(memstr);
            var xml = XDocument.Parse(html.DocumentNode.OuterHtml);
            return ConvertXml(xml.Root.Element("html"));
        }
    }
}
